/* $Header: lf_cmds.c,v 2.2 01/10/02 10:29:20 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: lf_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* MODULE PURPOSE:   Contains commands that are used during            */
/*        development to testing.   These are not intended for use     */
/*        by the workstation, diagnostics, or manufacturing test.      */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

/*
 */

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <zone_status.h>
#include <status.h>
#include <p_status.h>

#include <error.h>

#include <mio.h>
#include <cmd_set.h>
#include <method.h>
#include <hostutil.h>

#include <cmd_tbls.h>

#include <p_ui.h>

#include <exception.h>
#include <err_handler.h>
#include <display.h>
#include <messages.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   MACROS                  */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static INT16 getMsg( U_INT16 msg_no, BIT8 *pbuf, INT32 value1, INT32 value2 )
{
   BIT8    *pstr;
   INT16   i;

   pstr = pbuf;

   for ( i=0; i<90 ; i++)  *pstr++ = 0;

   TransferMsg( msg_no, pbuf, value1, value2 );

   /* Now find the length of the string */
   pstr = pbuf;
   i    = 0;
   while ( *pstr++ != 0 ) i++;

   return  i;
}


/***********************************************************************/
/* FUNCTION: DoTPEP                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Output the pop-up display contents for an exception.       */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  TransferMsg                                                 */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

INT16 DoTPEP(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16   parm_len;
   INT32   exception;
   U_INT16 msg_no;
   UI_ERR  error;

   (void)p_cmd;
   parm_len = 0;

   error = DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &exception );

   if (( error != OK ) || ( ValidExceptionIndex( (EXCEPTION)exception ) == FALSE ))
   {
      return parm_len;
   }

   msg_no = GetPopUpMsgNo( (EXCEPTION)exception );

   if ( msg_no == NO_MSG )
   {
      return parm_len;
   }

   return getMsg( msg_no, p_resp_parm, 0, 0 );
}

/***********************************************************************/
/* END FUNCTION: DoTPEP                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoTPEG                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Output the GLP display contents for an exception.          */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  TransferMsg                                                 */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

INT16 DoTPEG(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16   parm_len;
   INT32   exception, line_no, value1, value2;
   U_INT16 msg_no;
   UI_ERR  error;

   (void)p_cmd;
   parm_len = 0;

   error = DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &exception );

   if (( error != OK ) || ( ValidExceptionIndex( (EXCEPTION)exception ) == FALSE ))
   {
      return parm_len;
   }

   if ( (error=DecToInt( &p_cmd->parms[p_cmd->parmv[2]], 0, &line_no )) != OK )
   {
      CmdErrorHandler( p_cmd, 1, error );     /* invalid param */
      return parm_len;
   }

   value1 = value2 = 0;

   switch ( line_no )
   {
      case 1:  msg_no = DEVIATIONS_TITLE_MSG;
               value1 = value2 = exception;
               break;
      case 2:  msg_no = Exception_Info[ exception ].glp_hdr_msg;
               break;
      case 3:  msg_no = GetGlpMsgNo( (EXCEPTION)exception, 0 );
               break;
      case 4:  msg_no = AT_RUNTIME_MSG;
               break;
      default: msg_no = NO_MSG;
   }

   if ( msg_no == NO_MSG )
   {
      return parm_len;
   }

   return getMsg( msg_no, p_resp_parm, value1, value2 );
}

/***********************************************************************/
/* END FUNCTION: DoTPEG                                                */
/***********************************************************************/

INT16 DoTPEL(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16   parm_len;
   INT32   exception;
   U_INT16 msg_no;
   UI_ERR  error;

   (void)p_cmd;
   parm_len = 0;

   error = DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &exception );

   if (( error != OK ) || ( ValidExceptionIndex( (EXCEPTION)exception ) == FALSE ))
   {
      return parm_len;
   }

   msg_no = (U_INT16)GetStatusMsgNo( (EXCEPTION)exception );

   if ( msg_no == NO_MSG )
   {
      return parm_len;
   }

   return getMsg( msg_no, p_resp_parm, 0, 0 );
}

/***********************************************************************/
/* END FUNCTION: DoTPEL                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoTPPK                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Peek or poke pnuematic dsp memory.                         */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:  TP_Parm                                              */
/*                                                                     */
/* CALLS:  PcbPeek, PcbPoke                                            */
/*                                                                     */
/* LIMITATIONS:  This is for instrument development only.              */
/*                                                                     */
/***********************************************************************/

INT16 DoTPPK(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{

   U_INT16  length;
   INT32    param_index;
   UI_ERR   error;
   U_INT32  type;


   error = OK;
   length = 0;

   if ( IamAdirtball() )
   {
      return PutIntParam( (INT32)NOT_ALLOWED,p_resp_parm,0 );
   }

   if ( p_cmd->parmv[0] < 2 )
   {
      return PutIntParam( (INT32)MISSING_PARAM,p_resp_parm,0 );
   }

   /* Get read/write test type */
   type = p_cmd->parms[0] - '0';

   /* Get the the address */
   param_index = 2;

   if( StrLen( &p_cmd->parms[p_cmd->parmv[param_index]]) != 0 )
   {
       error = SetWkfileParam(&p_cmd->parms[p_cmd->parmv[param_index]],
                              &mTPPK , param_index-1 );
   }
   else
   {
      error = MISSING_PARAM;
   }

   param_index++;

   if ( error == OK )
   {
      switch( type )
      {
         case 0:
            /* read address location */

            /* First put down the result code and comma separator */
            length = PutIntParam( (INT32)error,p_resp_parm,0 );
            length += PutAsciiParam((BIT8 *)",",p_resp_parm+length );

            error = GetWkfileParam( p_resp_parm+length, &mTPPK, param_index-1 );
            length += StrLen(p_resp_parm+length);

            /* Remove the comma separator if an error occurred */
            if ( error != OK )
            {
               length--;
            }
            break;

         case 1:
            /* write to address location */
            if ( error == OK )
            {
               error = SetWkfileParam(&p_cmd->parms[p_cmd->parmv[param_index]],
                                      &mTPPK, param_index-1 );
            }

            /* Put down the result code */
            length = PutIntParam( (INT32)error,p_resp_parm,0 );

            break;

         default:
            length = PutIntParam( (INT32)INVALID_PARAM,p_resp_parm,0 );
      }
   }
   else
   {
      length = PutIntParam( (INT32)error,p_resp_parm,0 );
   }

   return length;
}

/***********************************************************************/
/* END FUNCTION: DoTPPK                                                */
/***********************************************************************/
